import logging
import requests
from zeep import Client
from zeep.transports import Transport
from modules.schema.oraclesrv import OracleSrv
from modules.schema.mssqlsrv import MSSQL
from config.base_config import WEB_ADDRESS, ORCL_HIS, MSSQL_LIS, MSSQL_PACS, MSSQL_AIMS

import sys
reload(sys)
sys.setdefaultencoding('utf8')

LOG = logging.getLogger("oldaudit")

requests.adapters.HTTPAdapter(pool_connections=100, pool_maxsize=100)
cli_session = requests.Session()
transport = Transport(session=cli_session, timeout=10)
client = Client(WEB_ADDRESS, transport=transport)

# get his db
def init_DB():
    """
    init db.
    """
    his_obj = OracleSrv(ORCL_HIS['host'], ORCL_HIS['port'], \
        ORCL_HIS['username'], ORCL_HIS['password'], ORCL_HIS['dsn'])

    pacs_obj = MSSQL(MSSQL_PACS['host'], MSSQL_PACS['port'], MSSQL_PACS['username'], \
        MSSQL_PACS['password'], MSSQL_PACS['database'], charset='utf8')

    lis_obj = MSSQL(MSSQL_LIS['host'], MSSQL_LIS['port'], MSSQL_LIS['username'], \
        MSSQL_LIS['password'], MSSQL_LIS['database'], charset='utf8')

    aims_obj = MSSQL(MSSQL_AIMS['host'], MSSQL_AIMS['port'], MSSQL_AIMS['username'], \
        MSSQL_AIMS['password'], MSSQL_AIMS['database'], charset='utf8')

    return his_obj, lis_obj, pacs_obj, aims_obj

hisdb = init_DB()[0]
lisdb = init_DB()[1]
pacsdb = init_DB()[2]
aimsdb = init_DB()[3]
